#include <func.h>

int main(int argc,char **argv)
{
    ARGS_CHECK(argc,3);
    int fdw = open(argv[1],O_WRONLY);
    ERROR_CHECK(fdw,-1,"open_fdw");
    int fdr = open(argv[2],O_RDONLY);
    ERROR_CHECK(fdr,-1,"open_fdr");
    
    printf("i am chat2:\n");
    int ret = 0;
    char buf[512] = {0};
    while(1)
    {
        memset(buf,0,sizeof(buf));
        ret = read(fdr,buf,sizeof(buf));
        ERROR_CHECK(ret,-1,"read_fdr");
        printf("      recive : %s\n",buf);

        memset(buf,0,sizeof(buf));
        ret = read(STDIN_FILENO,buf,sizeof(buf));
        ERROR_CHECK(ret,-1,"read_stdin");
        if(strlen(buf)-1==0)
        {
            printf("only enter,restart\n");
            continue;
        }
        write(fdw,buf,strlen(buf)-1);

    }

    return 0;
}


